﻿using System;
using System.Collections.Generic;
using System.Linq;
using Pixels.Logic;
using Sargon;
using Pixels.Rendering;

namespace Pixels.Interface
{
    class TechWindow : Window
    {
        public TechWindow(string title, int x, int y, int w, int h) : base(title, x,y,w,h) {

        }
    }

    class TechButton : Button
    {

        public TechButton(Technologies tech, int x, int y, int w, int h) : base("", x, y, w, h) {
            this.techID = tech;
        }

        public readonly Logic.Technologies techID;

        public override void render() {

            if (!Visible) return;

            var label = GlobalConsts.getTechnology(techID).name;
            var description = GlobalConsts.getTechnology(techID).description;

            if (!techID.Allowed()) {
                label = "[not yet available]";
                description = "";
            }

            var spr = Render.spriteInBox("white", ScreenRect, true);
            spr.color = new Sargon.Color(1, 1, 1, 0.02f);
            if (IsHilit) spr.alpha = 0.1f;
            spr.zed = zed * 10f;

            var txt = Render.textInBox(label, ScreenRect, true);
            txt.verticalAlign = Text.VAlign.top;
            txt.color = Color.white;
            txt.zed = (zed + 1) * 10f;

            var t2 = Render.textInBox(description, ScreenRect.move(0, 15), true);
            txt.verticalAlign = Text.VAlign.top;
            t2.color = Color.grey(0.7f);
            t2.zed = (zed + 1) * 10f;
            t2.characterSize = 16;
                
            if (!techID.Allowed())   txt.color = Color.grey(0.8f);
            if (techID.Researched()) {
                txt.color = Color.white;
                txt.text += " (researched)";
            } else { 

            }

            

            if (World.CurrentResearch == techID) {
                var bulb = Render.spriteInBox("icon_bulb", new Ur.Rect(ScreenRect.x0 + 30, ScreenRect.y0, ScreenRect.h, ScreenRect.h), true);
                bulb.zed = (zed + 2) * 10f;
                var percentage = 100 * GlobalConsts.getTechnology(techID).researchInvested / GlobalConsts.getTechnology(techID).cost;
                txt.text += " (" + percentage + "%)";
            }
            
        }

    }
}
